﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>项目成本管理</title>
    <link href="~/Scripts/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js"></script> 
    <script src="~/Content/js/appendhandle.js"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />
    <script type="text/javascript">
   
        var lock = false;//全局操作锁
        $(function () {          
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "PMDNMgr", "KeyName": "PMDNMgr" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) {                         
                        data.toolbar.push({ "text": "编辑信息", "id": "btGantt", "iconCls": "icon-edit", "handler": "costMgr();" })
                        data.toolbar.push({ "text": "查看信息", "id": "btview", "iconCls": "icon-more", "handler": "costMgr();" })
                        var toolbar = getToolBar(data);      //common.js
                        if (data.search) {//判断是否有浏览权限 
                            $("#ui_pm_dg").datagrid({       //初始化datagrid
                                url: "/Project/GetPMList?&r=" + Math.random(),
                                striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                                idField: 'ProjectID',
                                sort: 'UpdateTime',
                                order: 'desc',
                                pageList: [20, 40, 60, 80, 100],
                                queryParams: {
                                },
                                frozenColumns: [[
                                               {
                                                   hidden: true,
                                                   title: 'ID',
                                                   field: 'ProjectID'
                                               },
                                                 {
                                                     width: '100',
                                                     title: '项目编码',
                                                     field: 'ProjectNo',
                                                     formatter: function (value, row, index) {
                                                         return value.length > 8 ? '<span title="' + value + '">' + value + '</span>' : value;
                                                     }
                                                 },
                                                 {
                                                     //width: '120',
                                                     title: '项目名称',
                                                     field: 'ProjectName',
                                                     formatter: function (value, row, index) {
                                                         return value.length > 8 ? '<span title="' + value + '">' + value + '</span>' : value;
                                                     }
                                                 }

                                ]],
                                columns: [[
                                     {
                                         field: 'status', title: '状态', sortable: false, width: 45,
                                         formatter: function (value, row, index) {
                                             var x;
                                             switch (value) {
                                                 case 0:
                                                     x = "待确认";
                                                     break;
                                                 case 1:
                                                     x = "已确认";
                                                     break;
                                                 case 2:
                                                     x = "已下达";
                                                     break;
                                                 case 3:
                                                     x = "已结项";
                                                     break;
                                                 case 5:
                                                     x = "已终止";
                                                     break;
                                                 default:
                                                     x = value;
                                                     break;
                                             }
                                             return x;
                                             //return value == 1 ? '<img src="../../Content/themes/icon/chk_checked.gif" alt="已确认" title="项目已确认" />' : '<img src="../../Content/themes/icon/chk_unchecked.gif" alt="未确认" title="项目未确认" />';
                                         }
                                     },
                                 { field: 'Department', title: '部门', sortable: false, hidden: false, formatter: function (value, row, index) {
                                         if (value) { return value.substring(0, 4); }
                                     } },
                                {
                                    field: 'ProjectClerk', title: '业务员', sortable: false, 
                                    hidden: false
                                },
                                {
                                    field: 'ProjectManager', title: '管理员', sortable: false, 
                                },
                                
                                  { field: 'UpdateBy', title: '更新人', width: 60 },
                                  { field: 'UpdateTime', title: '更新时间', sortable: true, width: 70, formatter: getDate },
                                  {
                                      field: 'Remark', title: '项目描述', width: 500,
                                      formatter: function (value, row, index) {
                                          return value.length > 20 ? '<span title="' + value + '">' + value + '</span>' : value;
                                      }
                                  },
                                  { field: 'CreateBy', title: '创建人', width: 60, hidden: true },
                                  { field: 'CreateTime', title: '创建时间', sortable: true, width: 70, formatter: getDate, hidden: true },

                                ]],
                                toolbar: toolbar.length == 0 ? null : toolbar,
                                onSelect: function (rowIndex, rowData) {                                                       
                                },
                                onLoadSuccess: function (data) {    

                                }
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })
            //回车搜索
            $("#ui_pm_search").find('input').on('keyup', function (event) {
                if (event.keyCode == '13') {
                    ui_pm_searchdata();
                }
            })
        });
       
        //成本管理功能模块
        function costMgr() {
            var row = $("#ui_pm_dg").datagrid("getSelected");
            if (row == null) {
                $.show_alert("提示", "请先勾选项目");
                return;
            }
            if (row.length > 1) {
                $.show_alert("提示", "不支持批量处理项目");
                $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            $("<div/>").dialog({
                id: "ui_pm_cost_dialog",
                href: "/Project/PMCost",
                queryParams: {
                    ProjectID: row.ProjectID,
                    ProjectNo: row.ProjectNo,
                    ProjectName: row.ProjectName,
                    IcmoNo: row.IcmoNo,//关联主单号
                    FitemNo: row.FitemNo,//关联物料
                    FModel: row.FModel,//关联物料
                    FName: row.FName,//关联物料                    
                    estcost: row.estCost,//预估成本
                    budCost: row.budCost,//预算成本
                    stdCost: row.stdCost,//标准成本
                    reaCost: row.reaCost,//实际成本

                },

                title: "成本管理",
                height: $(window).height(),
                width: $(window).width(),
                modal: true,
                toolbar: [],
                onClose: function () {
                    $("#ui_pm_cost_dialog").dialog('destroy');  //销毁dialog对象
                    $("#ui_pm_dg").datagrid("reload");//刷新主表
                }
            })

        }


        function ui_pm_searchdata() {
            $("#ui_pm_dg").datagrid('load', {
                ProjectNo: $('#txtProjectNo').val(),
                ProjectName: $('#txtPMName').val(),
                status: $('#FStatus').val(),
                CreateTimeS: $('#txtAddBeginDate').datetimebox('getValue'),
                CreateTimeE: $('#txtAddEndDate').datetimebox('getValue')
            });
            // $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
        }

        function ui_pm_cleardata() {
            $('#ui_pm_search input').val('');
            $('#ui_pm_search select').val('select');
            $('#txtAddBeginDate').datetimebox('setValue', '');
            $('#txtAddEndDate').datetimebox('setValue', '');
            $("#ui_pm_dg").datagrid('load', {});//清空条件自动加载数据
            //  $("#ui_pm_dg").datagrid('clearSelections').datagrid('clearChecked');
        }      
   
    </script>
</head>
<body>
    <div id="ui_pm_layout" class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'north',split:true,border:true,collapsed:true" title="条件搜索" style="height:104px;">
            <div id="ui_pm_search">
                <table class="tableForm" style="width: 99%; height: 100%; background: #F5F5F5;">
                    <tr>
                        <th>
                            项目编码：
                        </th>
                        <td>
                            <input name="txtProjectNo" id="txtProjectNo" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>

                        <th>
                            项目名称：
                        </th>
                        <td>
                            <input name="txtPMName" id="txtPMName" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>

                        <th>
                            项目状态：
                        </th>
                        <td>
                            <select name="FStatus" id="FStatus">
                                <option value="select">请选择</option>
                                <option value="0">未确认</option>
                                <option value="1">已确认</option>
                                <option value="2">已下达</option>
                                <option value="3">已完成</option>
                            </select>
                        </td>

                    <tr>
                        <th>
                            添加时间：
                        </th>
                        <td>
                            <input name="txtAddBeginDate" id="txtAddBeginDate" class="easyui-datetimebox"
                                   editable="false" style="width:150px;height:22px;" />
                        </td>

                        <th>
                            至：
                        </th>
                        <td>
                            <input name="txtAddEndDate" id="txtAddEndDate" class="easyui-datetimebox"
                                   editable="false" style="width:150px;height:22px;" />
                        </td>
                        <td colspan="4">
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                               onclick="ui_pm_searchdata();">搜索</a>
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                               onclick="ui_pm_cleardata();">清空条件</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div data-options="region:'center',border:false">
            <table id="ui_pm_dg" data-options="fit:true,border:false"></table>
        </div>
    </div>
     
   

   

    

</body>
</html>